package com.chenshu.controller;

import com.chenshu.domain.LoginUser;
import com.chenshu.validator.LoginUserValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-04-29
 * Time：16:01
 */
@Controller
public class LoginUserController {
    @Autowired
    private LoginUserValidator loginUserValidator;

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String loginForm(Model model) {
        model.addAttribute("loginUser", new LoginUser());
        return "login";
    }

    public String login(LoginUser loginUser, Model model, Errors errors) {
        model.addAttribute("loginUser", loginUser);
        loginUserValidator.validate(loginUser, errors);
        if (errors.hasErrors()) {
            return "login";
        }
        return "msg";
    }
}
